

#ifndef RVIZ_COMMON__NEW_OBJECT_DIALOG_HPP_
#define RVIZ_COMMON__NEW_OBJECT_DIALOG_HPP_

#include <QDialog>

#include <rviz_common/factory/factory.hpp>

class QTreeWidget;
class QTreeWidgetItem;
class QTextBrowser;
class QLineEdit;
class QDialogButtonBox;

namespace rviz_common
{

class NewObjectDialog : public QDialog
{
    Q_OBJECT

public:
    /// Dialog for choosing a new object to load with a pluginlib ClassLoader.
    /***
   * \param disallowed_display_names set of display names to prevent
   *   the user from using.
   *
   * \param disallowed_class_lookup_names set of class lookup names to
   *   prevent the user from selecting.  Names found in the class loader
   *   which are in this list will appear disabled.
   *
   * \param lookup_name_output Pointer to a string where dialog will
   *   put the class lookup name chosen.
   *
   * \param display_name_output Pointer to a string where dialog will
   *   put the display name entered, or NULL (default) if display
   *   name entry field should not be shown.
   */
    NewObjectDialog(
        Factory * factory,
        const QString & object_type,
        const QStringList & disallowed_display_names,
        const QStringList & disallowed_class_lookup_names,
        QString * lookup_name_output,
        QString * display_name_output = 0,
        QWidget * parent = 0);

    virtual QSize sizeHint() const;

public Q_SLOTS:
    virtual void accept();

private Q_SLOTS:
    void onDisplaySelected(QTreeWidgetItem * selected_item);
    void onNameChanged();

private:
    /// Fill the tree widget with classes from the class loader.
    void fillTree(QTreeWidget * tree);

    /// Returns true if entered display name is non-empty and unique and if lookup name is non-empty.
    bool isValid();

    /// Display an error message to the user, or clear the previous one if error_text is empty.
    void setError(const QString & error_text);

    Factory * factory_;
    const QStringList & disallowed_display_names_;
    const QStringList & disallowed_class_lookup_names_;

    QString * lookup_name_output_;
    QString * display_name_output_;

    /// Widget showing description of the class.
    QTextBrowser * description_;

    QLineEdit * name_editor_;

    /// Widget with OK and CANCEL buttons.
    QDialogButtonBox * button_box_;

    /// Current value of selected class-lookup name.
    /**
   * Copied to `*lookup_name_output_` when "ok" is clicked.
   */
    QString lookup_name_;
};

}  // namespace rviz_common

#endif  // RVIZ_COMMON__NEW_OBJECT_DIALOG_HPP_
